#!/bin/bash

# 备份当前的 sources.list 文件
echo "正在备份当前的 sources.list 文件..."
cp /etc/apt/sources.list /etc/apt/sources.list.bak

# 输出替换完成的提示
echo "已备份当前的 sources.list 文件为 /etc/apt/sources.list.bak"

# 替换为阿里云源
echo "正在替换为阿里云源..."

cat << EOF > /etc/apt/sources.list
deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
EOF

# 更新 apt 索引
echo "替换完成，正在更新 apt 索引..."
apt-get update

# 提示完成
echo "镜像源已成功替换为阿里云，更新完成。"

